/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.core.utils.validation;

import java.util.Map;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.ui.action.ValidateAction;
/**
 * this class is used to create a Diagnostician
 * this code is adapted from {@link ValidateAction}
 * @author patrick Tessier
 *
 */
public class PapyrusDiagnostician  extends Diagnostician{
	protected AdapterFactory adapterFactory =null;

	/**
	 * create a diagnostician from adapterfactory 
	 * @param adapterFactory {@link AdapterFactory}
	 */
	public PapyrusDiagnostician(AdapterFactory adapterFactory) {
		super();
		this.adapterFactory=adapterFactory;
	}
	/**
	 * create a diagnostician from adapterfactory 
	 * @param validatorRegistry {@link Registry}
	 * @param adapterFactory {@link AdapterFactory}
	 */
	public PapyrusDiagnostician(Registry validatorRegistry,AdapterFactory adapterFactory) {
		super(validatorRegistry);
		this.adapterFactory=adapterFactory;
	}

	@Override
	/* comes from validationAction*/
	public String getObjectLabel(EObject eObject)
	{
		if (adapterFactory != null && !eObject.eIsProxy())
		{
			IItemLabelProvider itemLabelProvider = (IItemLabelProvider)adapterFactory.adapt(eObject, IItemLabelProvider.class);
			if (itemLabelProvider != null)
			{
				return itemLabelProvider.getText(eObject);
			}
		}
		return super.getObjectLabel(eObject);
	}


	public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context)
	{
		return super.validate(eClass, eObject, diagnostics, context);
	}

}
